home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / dialjb / dlgjb2.frm < prev    next >
Encoding:
Text File  |  1995-12-05  |  10.3 KB  |  276 lines

  1. 'DLGJB2.FRM
  2. '
  3. 'This file is strictly speaking not a Visual Basic form, but it contains
  4. 'Commands that should go into a Visual Basic form to properly use the
  5. 'DialogJB Dialog Box.
  6.  
  7. '****************************************************************************
  8. 'This is what to use on the Main form to open the dialog box.
  9. 'The sample uses a Command Button, but clearly a menu or other device
  10. 'would work just as well.
  11. 'The sample also loads the files chosen by the Dialog Box into a
  12. 'Combo Box on the main form.  You may want to vary this depending on
  13. 'the kind of control you want and whether you are loading single or
  14. 'multiple files.
  15.  
  16. Sub cmdGetFile_Click ()  'Or mnuGetFile_Click () etc.
  17.     cboFile.Clear 'This clears the Combo File
  18.  
  19. 'At this point you may want to clear other containers or information
  20. 'already loaded into your program.  You may want to save the current
  21. 'file.  
  22.  
  23.     Load frmDialogJB
  24.  
  25. 'You also need to draw a horizontal line called LinShadB on your Main form.
  26. 'Make this line invisible (LinShadB.Visible = False). It only appears
  27. 'When the DialogJB box is loaded to provide some shading and give a
  28. '3D effect.
  29.  
  30. LinShadB.X1 = 0
  31. LinShadB.X2 = frmMain.ScaleWidth
  32. LinShadB.Y1 = ((frmDialogJB.ScaleHeight + (frmMain.ScaleHeight - frmDialogJB.ScaleHeight) / 2)) - 110
  33. LinShadB.Y2 = ((frmDialogJB.ScaleHeight + (frmMain.ScaleHeight - frmDialogJB.ScaleHeight) / 2)) - 110
  34.         LinShadB.Visible = True
  35. End Sub
  36.  
  37. '******************************************************************************
  38. 'The following items go in one of your MODULEx.BAS files.  They are
  39. 'called by DialogJB for shading and centering.  They are optional.
  40. 'The CenterForm routine is useful for most forms.
  41.  
  42.  
  43. 'This gives a 3D effect to most gray colored controls.
  44. 'I'm pretty sure I adpated this from Visual Basic Programmer's Journal,
  45. 'but I don't know which issue.
  46. Sub Go3dGray (myForm As Form, myCtl As Control)
  47.     myForm.CurrentX = myCtl.Left - 15
  48.     myForm.CurrentY = myCtl.Top + myCtl.Height
  49.     myForm.Line -Step(0, -(myCtl.Height + 15)), RGB(92, 92, 92)
  50.     myForm.Line -Step(myCtl.Width + 15, 0), RGB(92, 92, 92)
  51.     myForm.Line -Step(0, myCtl.Height + 15), RGB(255, 255, 255)
  52.     myForm.Line -Step(-(myCtl.Width + 15), 0), RGB(255, 255, 255)
  53.  
  54. End Sub
  55.  
  56. 'This gives a 3D effect to the border of any gray form. I used it on
  57. 'on the main form as well.
  58. Sub BordGray3d (myForm As Form)
  59.     myForm.Line (15, 15)-((myForm.ScaleWidth - 15), 15), RGB(255, 255, 255)
  60.     myForm.Line (15, 15)-(15, (myForm.ScaleHeight - 15)), RGB(255, 255, 255)
  61.     myForm.Line ((myForm.ScaleWidth - 15), 0)-((myForm.ScaleWidth - 15), myForm.ScaleHeight), RGB(0, 0, 0)
  62.     myForm.Line (0, myForm.ScaleHeight - 15)-(myForm.ScaleWidth, myForm.ScaleHeight - 15), RGB(0, 0, 0)
  63.     myForm.Line (15, (myForm.ScaleHeight - 30))-((myForm.ScaleWidth - 15), (myForm.ScaleHeight - 30)), RGB(92, 92, 92)
  64.     myForm.Line ((myForm.ScaleWidth - 30), 15)-((myForm.ScaleWidth - 30), (myForm.ScaleHeight - 15)), RGB(92, 92, 92)
  65. End Sub
  66.  
  67. 'This is useful routine to center any form on the screen.
  68. 'I got this from Teach Yourself Visual Basic 3.0 by John Socha and
  69. 'Devra Hall.
  70. Sub CenterForm (aForm As Form)
  71.     Dim X, Y                    ' New top, left for the form
  72.  
  73.     X = (Screen.Width - aForm.Width) / 2
  74.     Y = (Screen.Height - aForm.Height) / 2
  75.     aForm.Move X, Y             ' Change location of the form
  76. End Sub
  77.  
  78. 'For the GetINIItem$ function and the SetINI subroutine, see the 
  79. 'file INIDEMO.ZIP by Curtis Smith available as a free download on many
  80. 'BBS's and online services. (Look for Visual Basic or Windows API topics.)
  81.  
  82. Sub GetINIList (ByVal FileName$, ByVal ListName$, NumElems, ListArray$())
  83.    GroupName$ = "[LIST " + ListName$ + "]"
  84.    Call SetINIParams(FileName$, GroupName$, LineItem$)
  85.  
  86.    INIFileNum = FreeFile
  87.    Open FileName$ For Input As #INIFileNum
  88.    While Not EOF(INIFileNum)
  89.       Call FindGroup(GroupName$, Found)
  90.       If Found = True Then
  91.          Line Input #INIFileNum, Lne$
  92.          Temp$ = ParseES$(Lne$, Value$)
  93.          NumElems = Val(Value$)
  94.          ReDim ListArray$(NumElems)
  95.          For CX = 1 To NumElems
  96.             Line Input #INIFileNum, ListArray$(CX)
  97.          Next CX
  98.       End If
  99.    Wend
  100.    Close #INIFileNum
  101.  
  102. End Sub
  103.  
  104. Function GetINIValue$ (ByVal FileName$, ByVal GroupName$, ByVal LineItem$)
  105.    Call SetINIParams(FileName$, GroupName$, LineItem$)
  106.  
  107.    INIFileNum = FreeFile
  108.    Open FileName$ For Input As #INIFileNum
  109.    While Not EOF(INIFileNum)
  110.       Call FindGroup(GroupName$, Found)
  111.       If Found = True Then
  112.          FoundValue$ = FindItem$(LineItem$)
  113.       End If
  114.    Wend
  115.    Close #INIFileNum
  116.  
  117.    ' Strip all spaces and leading-trailing quotes
  118.    Temp$ = LTrim$(RTrim$(FoundValue$))
  119.    If Left$(Temp$, 1) = Chr$(34) Then Temp$ = Mid$(Temp$, 2)
  120.    If Right$(Temp$, 1) = Chr$(34) Then Temp$ = Left$(Temp$, Len(Temp$) - 1)
  121.    Temp$ = LTrim$(RTrim$(FoundValue$))
  122.  
  123.    GetINIValue = Temp$
  124.  
  125. End Function
  126.  
  127. Sub SetINIItem (ByVal FileName$, ByVal GroupName$, ByVal LineItem$, ByVal LineItemValue$)
  128.    Call SetINIParams(FileName$, GroupName$, LineItem$)
  129.  
  130.    ' Open the CURRENT ini (if one exists)
  131.    If Dir$(FileName$) = "" Then
  132.       INIFileNum = FreeFile
  133.       Open FileName$ For Output As #INIFileNum
  134.       TempFileNum = FreeFile
  135.       Open "C:\INItemp.ini" For Output As #TempFileNum
  136.       Print #TempFileNum, GroupName$
  137.       Print #TempFileNum, LineItem$; "="; LineItemValue$
  138.       Print #TempFileNum, " "
  139.  
  140.    Else
  141.       ' Open the TEMP file for inputing into
  142.       TempFileNum = FreeFile
  143.       Open "C:\INItemp.ini" For Output As #TempFileNum
  144.       INIFileNum = FreeFile
  145.       Open FileName$ For Input As #INIFileNum
  146.  
  147.  
  148.       ' Look for the Group
  149.       Done = False
  150.       Found = False
  151.       Printed = False
  152.       Do
  153.          Line Input #INIFileNum, Lne$  ' Read the Line
  154.          If UCase$(Lne$) = GroupName$ Then
  155.             Found = True
  156.             Done = True
  157.          End If
  158.          If EOF(INIFileNum) Then Done = True
  159.          Print #TempFileNum, Lne$       ' Print the Line
  160.       Loop Until Done
  161.  
  162.       If Found = False Then
  163.          ' Group not found,  GO ADD A NEW ONE...
  164.          Print #TempFileNum, " "
  165.          Print #TempFileNum, GroupName$
  166.          Print #TempFileNum, LineItem$; "="; LineItemValue$
  167.          Printed = True
  168.       Else
  169.          ' We found the group - now look for the Item
  170.          Done = False
  171.          Found = False
  172.          Do
  173.             Line Input #INIFileNum, Lne$
  174.             If EOF(INIFileNum) Then Done = True
  175.             If Len(Lne$) = 0 And Done = True Then
  176.                ' We reached the eof WITHOUT finding the ITEM
  177.                Done = True
  178.                Print #TempFileNum, LineItem$; "="; LineItemValue$
  179.                Print #TempFileNum, " "
  180.                Printed = True
  181.             Else
  182.                If Left$(Lne$, 1) = "[" Then
  183.                   ' We found the next group WITHOUT finding the ITEM
  184.                   Print #TempFileNum, LineItem$; "="; LineItemValue$  ' Add Item
  185.                   Print #TempFileNum, " "
  186.                   Print #TempFileNum, Lne$                            ' Add NEXT GROUP
  187.                   Done = True
  188.                   Printed = True
  189.                ElseIf Lne$ <> "" Then
  190.                   If ParseES$(Lne$, TempVal$) = LineItem$ Then
  191.                      Found = True
  192.                      Print #TempFileNum, LineItem$; "="; LineItemValue$
  193.                      Done = True
  194.                      Printed = True
  195.                   Else
  196.                      Print #TempFileNum, Lne$
  197.                   End If
  198.                End If
  199.             End If
  200.          Loop Until Done
  201.  
  202.          If Printed = False Then
  203.             ' We made it this far - and have NOT written the item
  204.             Print #TempFileNum, LineItem$; "="; LineItemValue$
  205.          End If
  206.  
  207.          ' Add the REST OF THE FILE
  208.          If Not EOF(INIFileNum) Then
  209.             Do
  210.                Line Input #INIFileNum, Lne$
  211.                Print #TempFileNum, Lne$
  212.             Loop Until EOF(INIFileNum)
  213.          End If
  214.       End If
  215.    End If
  216.    Close #INIFileNum
  217.    Close #TempFileNum
  218.    Kill FileName$
  219.    Name "C:\INItemp.ini" As FileName$
  220.  
  221. End Sub
  222.  
  223. Sub SetINIParams (FileName$, GroupName$, LineItem$)
  224.    FileName$ = LTrim$(RTrim$(UCase$(FileName$)))
  225.    GroupName$ = LTrim$(RTrim$(UCase$(GroupName$)))
  226.    LineItem$ = LTrim$(RTrim$(UCase$(LineItem$)))
  227.  
  228.  
  229.    ' Setup FileName$
  230.    Select Case FileName$
  231.       Case "WIN", "WIN.INI"
  232.          FileName$ = "C:\WINDOWS\WIN.INI"
  233.  
  234.       Case "SYSTEM", "SYSTEM.INI"
  235.          FileName$ = "C:\WINDOWS\SYSTEM.INI"
  236.       
  237.       Case Else
  238.          If InStr(FileName$, "WINDOWS") = 0 Then
  239.             FileName$ = "C:\Windows\" + FileName$
  240.             If InStr(FileName$, ".") = 0 Then FileName$ = FileName$ + ".INI"
  241.          End If
  242.  
  243.    End Select
  244.  
  245.    ' Setup GroupName$
  246.    If Left$(GroupName$, 1) <> "[" Then GroupName$ = "[" + GroupName$
  247.    If Right$(GroupName$, 1) <> "]" Then GroupName$ = GroupName$ + "]"
  248.  
  249. End Sub
  250.  
  251. '  "This program is produced by a member of the Association of Shareware
  252. '    Professionals (ASP).  ASP wants to make sure that the shareware
  253. '    principle works for you. If you are unable to resolve a
  254. '    shareware-related problem with an ASP member by contacting the member
  255. '    directly, ASP may be able to help. The ASP Ombudsman can help you
  256. '    resolve a dispute or problem with an ASP member, but does not provide
  257. '    technical support for members' products.  Please write to the ASP
  258. '    Ombudsman at 545 Grover Road, Muskegon, MI USA 49442-9427, Fax
  259. '    616-788-2765, or send a CompuServe message via CompuServe Mail to ASP
  260. '    Ombudsman 70007,3536 (or e-mail 70007.3536@compuserve.com)."
  261. '
  262. '    Member, Educational Software Cooperative (ESC).
  263. '
  264. 'Copyright ⌐ 1995, James Bair, All rights reserved.
  265. 'Portions taken from sources as indicated.
  266. '
  267. '                                    ____|__     |                 «
  268. ' P.O. Box 203                    --|       |    |-------------------
  269. ' Shelton CT 06484-0203  USA        |   ____|__  |  Association of
  270. '                                   |  |       |_|  Shareware
  271. '                                   |__|   o   |    Professionals
  272. ' CompuServe: 70730,3001          -----|   |   |---------------------
  273. ' Internet: 70730.3001@compuserve.com  |___|___|    MEMBER
  274. '  (Queries only) jbair@csunet.ctstateu.edu
  275. '
  276.